{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.14 Bernoulli's Theorem-Water"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Water at 15 degrees Celsius is flowing through the piping system shown in Crane TP 410M's example at 1500 L/min.\n",
    "\n",
    "Calculate the velocity in both 4 and 5 inch sizes; and the pressure drop.\n",
    "\n",
    "Note: This problem suggests to handle the changing size elbow by adding on the result of a smooth expansion, which is also used here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "262809.7611610049 pascal"
      ],
      "text/latex": [
       "$262809.7611610049\\ \\mathrm{pascal}$"
      ],
      "text/plain": [
       "262809.7611610049 <Unit('pascal')>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from math import *\n",
    "from fluids.units import *\n",
    "from thermo.units import Chemical\n",
    "\n",
    "water = Chemical('water', P=2*u.bar, T=15*u.degC)\n",
    "rho = water.rho\n",
    "mu = water.mu\n",
    "\n",
    "Q = 1500*u.L/u.min\n",
    "r_d = 1.5\n",
    "_, D1, _, _ = nearest_pipe(Di=100*u.mm)\n",
    "_, D2, _, _ = nearest_pipe(Di=125*u.mm)\n",
    "L1 = 34*u.m\n",
    "L2 = (22+45)*u.m\n",
    "dH = 22*u.m\n",
    "beta = D1/D2\n",
    "\n",
    "V1 = Q/(pi/4*D1**2)\n",
    "V2 = Q/(pi/4*D2**2)\n",
    "Re1 = Reynolds(rho=rho, mu=mu, V=V1, D=D1)\n",
    "Re2 = Reynolds(rho=rho, mu=mu, V=V2, D=D2)\n",
    "fd1 = friction_factor(Re=Re1, eD=0.0018*u.inch/D1)\n",
    "fd2 = friction_factor(Re=Re2, eD=0.0018*u.inch/D2)\n",
    "fd = (fd1+fd2)/2\n",
    "\n",
    "dP = rho*u.gravity*dH\n",
    "\n",
    "K_D1 = bend_rounded(Di=D1, angle=90*u.degrees, fd=fd, bend_diameters=r_d)\n",
    "K_D1 += diffuser_conical(D1, D2, angle=30*u.degrees, fd=fd)\n",
    "K_D1 += K_from_f(fd=fd1, L=L1, D=D1)\n",
    "\n",
    "K_D2 = bend_rounded(Di=D2, angle=90*u.degrees, fd=fd, bend_diameters=r_d)\n",
    "K_D2 += K_from_f(fd=fd2, L=L2, D=D2)\n",
    "\n",
    "dP += dP_from_K(K=K_D1, rho=rho, V=V1)\n",
    "dP += dP_from_K(K=K_D2, rho=rho, V=V2)\n",
    "dP.to(u.Pa)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The result calculated in Crane's TP 410m is 26450 Pa. Their friction factor is 0.018. Again, it that value is used, the result calculated matches theirs - except this is off by an order of magnitude.\n",
    "\n",
    "In this edition, the gravitational term was forgotten. The prior 8th edition lists a value of 2.6 bar as the result for this problem. If their friction factor is used with this model, the following calculates a pressure drop of 2.62 bar."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "262439.4308380222 pascal"
      ],
      "text/latex": [
       "$262439.4308380222\\ \\mathrm{pascal}$"
      ],
      "text/plain": [
       "262439.4308380222 <Unit('pascal')>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fd = fd1 = fd2 = .018\n",
    "dP = rho*u.gravity*dH\n",
    "\n",
    "K_D1 = bend_rounded(Di=D1, angle=90*u.degrees, fd=fd, bend_diameters=r_d)\n",
    "K_D1 += contraction_round(D1, D2, r_d*D1)\n",
    "K_D1 += K_from_f(fd=fd1, L=L1, D=D1)\n",
    "\n",
    "K_D2 = bend_rounded(Di=D2, angle=90*u.degrees, fd=fd, bend_diameters=r_d)\n",
    "K_D2 += K_from_f(fd=fd2, L=L2, D=D2)\n",
    "\n",
    "dP += dP_from_K(K=K_D1, rho=rho, V=V1)\n",
    "dP += dP_from_K(K=K_D2, rho=rho, V=V2)\n",
    "dP.to(u.Pa)"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
